<?php

use Biz\cache\activity\CActivityIKEA;
use Doraemon\service\User;

ini_set('display_errors', 1);
error_reporting(-1);
require_once '/data/wwwroot/g_vendor/autoload.php';


echo <<<CODE
======== 参数列表 =========
cache 查看所有缓存
init 初始化缓存
======== end =========
CODE, PHP_EOL;

$action = $argv[1] ?? '';
$p = $argv[2] ?? 1;

switch ($action) {
    case 'cache':
        $cache = CActivityIKEA::allUserVote();
        echo implode("\t", ["uid", "昵称", "用户选择"]), PHP_EOL;
        $map = [1 => '喜欢', 2 => '不喜欢'];
        $uids = array_keys($cache);
        $nickMap = User::getusers_baisic_info($uids);
        $nickMap = $nickMap ? array_column($nickMap, 'nick', 'uid') : [];
        foreach ($cache as $uid => $selected) {
            echo implode("\t", [$uid, $nickMap[$uid] ?? '', $map[$selected]]), PHP_EOL;
        }

        $rank = CActivityIKEA::voteRanking();
        print_r($rank);
        break;
    case 'init':
        CActivityIKEA::clearVisitorVote();
        CActivityIKEA::clearVoteRanking();
        CActivityIKEA::clearVote();
        echo ('初始化成功');
        break;
}

